/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const ArticleHrefAdapter = require('../ArticleHrefAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const cheerio = require('cheerio');
const urlTool = require('url');

/**
 * 北京互金网
 * @type {module.Bjp2p}
 */
module.exports = class HeCaiJingKuaiXun extends ArticleHrefAdapter{

  parseHtml(html, linkRule){
    //将解析后的内容加载进解析器
    let $ = cheerio.load(html);

    let contents = [];
    let that = this;
    let rangeText = '';
    $(this.linkRule).each( function() {
        let liHtml = $(this).html();
        let $$ = cheerio.load(liHtml);
        let title = $$('.title').text().trim();
        title += ': ' + $$('.con').text().trim();
        let href = urlTool.resolve(that.requestUrl,  $$('.title').attr('href'));
     /* let title = $(this).text().trim();
        let href = '';
      if($(this).is('a') && $(this).attr('href')){
        href = urlTool.resolve(that.requestUrl, $(this).attr('href'));
      }*/

      if(title.length != 0 || href.length != 0){
        contents.push({
          title:title,
          href:href
        });
        rangeText +=title+href;
      }
    });
    console.log("----contents: " + JSON.stringify(contents))
    return {
      rangeText: rangeText,
      contents: contents
    };
  }



}
